package com.ddf.pluto.utils;

import com.ddf.publics.entity.Bid;
import com.ddf.publics.entity.User;
import com.ddf.publics.service.ConversionService;
import com.ddf.publics.service.UserService;
import com.ddf.publics.tool.Constant;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: dingding-financial
 * @description: 邀请人增加积分机制
 * @author: Mr.pluto
 * @create: 2020-07-03 08:30
 **/
@Component
public class InviteUtils {

    @Resource
    private UserService userService;
    @Resource
    private ConversionService conversionService;

    public void inviteUtils(Bid bid){
        User user = userService.queryById(bid.getInvestor());
        if(!"".equals(user.getInviteNum()) && user.getInviteNum()!=null){
//            根据邀请人手机号查询用户
            User inviteUser = new User();
            inviteUser.setPhone(user.getInviteNum());
            List<User> list = userService.queryListByUser(inviteUser);
            if(list.size()>0){
                inviteUser = list.get(0);
                //给当前登录的用户添加积分
                userService.userAddPoint(inviteUser, Constant.INVAESTMENT_INVITE);
                //把获得的积分记录在数据库中
                conversionService.userIntegralRecord(inviteUser,Constant.INVAESTMENT_INVITE,Constant.INVESTMENT_invite);
            }
        }
    }
}
